<!--
 * @Descripttion: 搜索工具类-模具
 * @LastEditors: xzh
 * @LastEditTime: 2023-09-15 21:10:23
-->
<template>
  <el-col :span="11">
    <el-input
      v-model="searchData.keyWord"
      clearable
      size="large"
      :placeholder="$t('page.moldManageArr.moldArchivesArr.searchCondition')"
    />
  </el-col>
  <el-col :span="11">
    <!-- 输入框选择对象 -->
    <DileInputSelectItem
      v-model="searchData.typeId"
      :selectType="selectTypeEnum.moldType"
      :expand-on-click-node="false"
      :placeholder="$t('common.select') + $t('page.moldManageArr.moldType')"
    />
  </el-col>
  <el-col :span="11">
    <!-- 输入框选择对象 -->
    <DileInputSelectItem
      v-model="searchData.positionId"
      :selectType="selectTypeEnum.position"
      :expand-on-click-node="false"
      :placeholder="$t('common.select') + $t('page.systemManageArr.position')"
    />
  </el-col>
  <el-col :span="11">
    <el-select
      v-model="searchData.statusId"
      size="large"
      :placeholder="$t('common.select') + $t('page.moldManageArr.moldState')"
    >
      <el-option
        v-for="item in searchMoldParam.moldStateArr"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </el-col>
</template>

<script setup lang="ts">
import { ref, reactive, toRef, onBeforeMount } from "vue";
import { selectTypeEnum } from "@/components/dile-selectItem/index.type";
import { object_Inf } from "@/utils/typings/index.type";
import DileInputSelectItem from "@/components/dile-selectItem/selectItem-input/index.vue";
import Dile_APi from "@/api";
import Dile_Methods from "@/utils/methods";

const props = defineProps({
  //搜索数据
  searchData: {
    type: Object,
    requited: true,
    default: {},
  },
});

/**
 * @Author: xzh
 * @Descripttion: 默认搜索数据
 * @Param:
 */
let defaultData = () => ({
  keyWord: "",
  typeId: null, //模具类型
  positionId: null, //存放位置
  statusId: null, //模具状态
});

/**
 * @Author: xzh
 * @Descripttion: 模具检索参数
 * @Param:
 */
let searchMoldParam = reactive<object_Inf>({
  moldStateArr: [],
});

/**
 * @Author: xzh
 * @Descripttion: 初始化
 * @Param:
 */
onBeforeMount(() => {
  reset();
  //加载搜索资源
  initSearchResource();
});

/**
 * @Author: xzh
 * @Descripttion: 加载搜索资源
 * @Param:
 */
let initSearchResource = async () => {
  await initMoldStateResource();
};

/**
 * @Author: xzh
 * @Descripttion: 加载模具状态资源
 * @Param:
 */
let initMoldStateResource = async () => {
  let moldStateArr = toRef(searchMoldParam, "moldStateArr");
  //加载所有模具状态
  moldStateArr.value = Dile_Methods.filterDataArr(
    (await Dile_APi.getMoldStateList()).map((state: object_Inf) => ({
      value: state.id,
      label: state.name,
    }))
  );
};
/**
 * @Author: xzh
 * @Descripttion: 重置
 * @Param:
 */
let reset = () => {
  Object.assign(props.searchData, defaultData());
};

defineExpose({
  reset,
});
</script>
<style lang="scss" scoped></style>
